class BorrowBooksController < ApplicationController
  # GET /borrow_books
  # GET /borrow_books.json
  before_filter :authenticate_user! , :only => [:index, :new,:create,:destroy,:edit]
  #def index
  #  @borrow_books = BorrowBook.all
  #
  #  respond_to do |format|
  #    format.html # index.html.erb
  #    format.json { render json: @borrow_books }
  #  end
  #end

  # GET /borrow_books/1
  # GET /borrow_books/1.json
  def show
    @borrow_book = BorrowBook.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @borrow_book }
    end
  end

  # GET /borrow_books/new
  # GET /borrow_books/new.json
  def new
    @borrow_book = BorrowBook.new
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @borrow_book }
    end
  end

  # GET /borrow_books/1/edit
  #def edit
  #  @borrow_book = BorrowBook.find(params[:id])
  #end

  # POST /borrow_books
  # POST /borrow_books.json
  def create
    @borrow_book = BorrowBook.new(params[:borrow_book])
    book=Book.find(@borrow_book.book_id)
    book.can_user=false
    respond_to do |format|
      if @borrow_book.save
        book.save
        format.html { redirect_to @borrow_book.book, notice: 'Borrow book was successfully created.' }
        format.json { render json: @borrow_book, status: :created, location: @borrow_book }
      else
        format.html { render action: "new" }
        format.json { render json: @borrow_book.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /borrow_books/1
  # PUT /borrow_books/1.json
  ##def update
  ##  @borrow_book = BorrowBook.find(params[:id])
  ##
  ##  respond_to do |format|
  ##    if @borrow_book.update_attributes(params[:borrow_book])
  ##      format.html { redirect_to @borrow_book, notice: 'Borrow book was successfully updated.' }
  ##      format.json { head :no_content }
  ##    else
  ##      format.html { render action: "edit" }
  ##      format.json { render json: @borrow_book.errors, status: :unprocessable_entity }
  ##    end
  ##  end
  #end

  # DELETE /borrow_books/1
  # DELETE /borrow_books/1.json
  #def destroy
  #  @borrow_book = BorrowBook.find(params[:id])
  #  @borrow_book.destroy
  #
  #  respond_to do |format|
  #    format.html { redirect_to borrow_books_url }
  #    format.json { head :no_content }
  #  end
  #end
end
